package week09

// 36. 有效的数独
// https://leetcode-cn.com/problems/valid-sudoku/

func isValidSudoku(board [][]byte) bool {
	var row = makeRecord()
	var col = makeRecord()
	var grid = makeRecord()
	for i := range board {
		for j := range board[i] {
			if board[i][j] == '.' {
				continue
			}
			index := board[i][j] - '0'
			gridId := i/3*3+j/3
			if row[i][index] || col[j][index] || grid[gridId][index] {
				return false
			}
			row[i][index] = true
			col[j][index] = true
			grid[gridId][index] = true
		}
	}
	return true
}

func makeRecord() [][]bool {
	var record = make([][]bool, 9)
	for i := range record {
		record[i] = make([]bool, 10)
	}
	return record
}
